// pages/home/friends/friends.js
import { getMyInviteList } from '../../../api/user'
const showCount = 20;
let currentPage = 1;
let totalPage = 1;
let loading = false;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    friends: []
  },
  onShow: function (options) {
     currentPage = 1;
      totalPage = 1;
      this.setData({
        friends: []
      })
      this.getMyInviteList()
  },

  getMyInviteList(){
    if(loading){
      return ;
    }
    loading = true
    getMyInviteList({
      showCount,
      currentPage,
    })
    .then(res => {
      
      loading=false

      totalPage = res.data.totalPage
      let friends = res?.data?.varList || []
      
      if(friends.length> 0){
        let prelist = this.data.friends
        this.setData({
          friends: prelist.concat(friends)
        })
        currentPage++
      }
    })
    .catch(err => {
      
      loading=false
    })


  },

  callPhone(e){
    
    const {phonenumber} =e.currentTarget.dataset
    
    wx.makePhoneCall({
      phoneNumber: phonenumber,
      success: function (res) {
        
      },
      fail: function (err) {
        
      },
    });
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (currentPage > totalPage) {

      wx.showToast({
        title: '已经到底了', icon: 'none'
      })
      return;
    }

    this.getMyInviteList();
  },

})